[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
mktemp() Create a Unique File Name
#include <dir.h> Required for declarations only
char *mktemp(template);
char *template; File name pattern
mktemp() creates a unique file name by modifying 'template'.
'template' has the form 'baseXXXXXX'. 'base' is the two-character
part of the new file name supplied by the user. The six Xs are place
holders for the part supplied by mktemp(). 'base' is saved and the
six trailing Xs are replaced with two letters, a dot, and an
extension of three letters.
Returns: A pointer to the modified template, if successful;
null value, if 'template' is badly formed or no more
unique names can be created.
Notes: mktemp() creates unique file names. It does not
create or open files.
-------------------------------- Example ---------------------------------
The following statements use mktemp() to create a unique file name
and then use this name to open a new file.
#include <dir.h>
#include <fcntl.h>
#include <sys\stat.h>
char *template = "nfXXXXXX";
char *fname;
int fhndl;
main()
{
fname = mktemp(template);
fhndl = open(fname,O_CREAT,S_IREAD|S_IWRITE);
printf("%s opened",fname);
close(fhndl);
}
See Also:
fopen()
open()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson